(function ($) {
    $.fn.scrollTable = function (options) {
        var defaults = {
            interval: options.interval || 3000,
            scrollByRow: options.scrollByRow||false,
            step: options.step||5,
        };
        var box = $(this).parent();
        var realTable = $(this);
        var scrollTop = ""
        // var cloneTable = $(this).find('.tb2');
        var step = defaults.scrollByRow?realTable.find('.tr').outerHeight(true):defaults.step;
        var scrollInterval=null,scrollIndex = 0;
        if (realTable.outerHeight() > box.outerHeight()) {
            // cloneTable.html(realTable.html());//克隆list1的数据，使得list2和list1的数据一样
            realTable.append(realTable.html())
            clearInterval(scrollInterval)
            scrollInterval = setInterval(scrollup, defaults.interval);//数值越大，滚动速度越慢
        }
        function scrollup() {
            console.log( defaults.scrollByRow,"defaults.scrollByRow")
            //滚动条距离顶部的值恰好等于list1的高度时，达到滚动临界点，此时将让scrollTop=0,让list1回到初始位置，实现无缝滚动
            var scrollTop = box.scrollTop() //box.scrollTop();
            defaults.scrollByRow && realTable.find('.tr').eq(scrollIndex).addClass('active').siblings().removeClass('active');
            scrollIndex ++;
            scrollTop += (step || 1);
            box.animate({
                scrollTop: scrollTop
            },defaults.scrollByRow?1000:0);
            if (scrollTop >= realTable.outerHeight()/2) {
                scrollIndex = 0;
                box.animate({
                    scrollTop:0
                },0);
            }
        }
        // 鼠标离开时，滚动继续
        box.on('mouseover',function () {
            clearInterval(scrollInterval);
        }).on('mouseout',function () {
           
            scrollInterval = setInterval(scrollup, defaults.interval);
        });
        return scrollInterval;
    };
})(jQuery);